--- interact_link: content/08/03/plotly8-3.ipynb kernel_name: python3 kernel_path: content/08/03 has_widgets: false title: |- Scatter Plots pagenum: 16 prev_page: url: /08/02/plotly8-2.html next_page: url: /08/04/plotly8-4.html suffix: .ipynb search: scatter id plots plot variable plotlyscatterplots ly python line scatterandlineplotwithgo good paired numerical data dependent multiple values value independent trying determine whether variables related plotlyscatterplotsbasic basic plotlyscatterplotscustomizing customizing comment: "***PROGRAMMATICALLY GENERATED, DO NOT EDIT. SEE ORIGINAL FILES IN /content***" ---
Scatter Plots

Scatter Plots

Scatter Plots are good to use:

  • When you have paired numerical data.
  • When your dependent variable may have multiple values for each value of your independent variable.
  • When trying to determine whether the two variables are related.

Basic Scatter Plot

import plotly.graph_objects as go
from plotly.offline import init_notebook_mode, plot
from IPython.core.display import display, HTML
init_notebook_mode(connected=True)
import numpy as np #Create random data with numpy

N = 1000
t = np.linspace(0, 10, 100)
y = np.cos(t)

#Make sure to specify markers in the mode
fig = go.Figure(data=go.Scatter(x=t, y=y, mode='markers'))

#show your plot
plot(fig, filename = 'figure8-3-1.html')
display(HTML('figure8-3-1.html'))

Customizing Scatter Plots

N = 1000
t = np.linspace(0, 10, 100)
y_0 = np.cos(t)
y_1 = np.sin(t)
y_2 = y_0 * 3
y_3 = y_1 / 3

fig = go.Figure()

# Add traces for each scatter
fig.add_trace(go.Scatter(x=t, y=y_0,
                    mode='markers',
                    name='Cosine', #name the marker
                    marker_color='lime')) #Change the marker color
fig.add_trace(go.Scatter(x=t, y=y_1,
                    mode='markers',
                    name='Sine',
                    marker_color = 'magenta'))
fig.add_trace(go.Scatter(x=t, y=y_2,
                    mode='markers',
                    marker_line_width=2, #change the marker width
                    marker_size=10, #Change the size of the marker
                    name='3 Cosine',
                    marker_color = 'hotpink'))

# Set options common to all traces (i.e title, background color)
fig.update_layout(title='Trigonometric FUNctions Click and Drag to Zoom In!',
                  plot_bgcolor = 'black')

plot(fig, filename = 'figure8-3-2.html')
display(HTML('figure8-3-2.html'))